<?php

namespace Application\Model;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Sql;


class ProjetTable extends AbstractTableGateway {
	
	protected $table ='projets';
	protected $tablename ='projets';
	
	public function __construct(Adapter $adapter) {
		$this->adapter = $adapter;
		$this->resultSetPrototype = new ResultSet(new Projet);
		$this->initialize();
	}
	
	public function fetchAll()
	{
		$resultSet = $this->select();
		return $resultSet;
	}
	
	
	public function SelectById($id)
	{

		$rowset = $this->select(array('id_projet' => $id));
		$row = $rowset->current();
		if (!$row) {
			//throw new \Exception("Could not find $username ");
			return null;
		}
		return $row;
		
	}
	
/*	
	public function SelectByIdBis($id)
	{
	
		select `nom_projet`,`description` from `projets`
		
		where `id_projet` IN (SELECT `id_projet` FROM `projets_users` WHERE
		`id_user` = 1)
		
		$rowset = $this->select(array('id_projet' => $id
		
		
		));
		$row = $rowset->current();
		if (!$row) {
			//throw new \Exception("Could not find $username ");
			return null;
		}
		return $row;
	
	}
	
	*/
	
	public function getService($id)
	{
		$id = (int) $id;
		$rowset = $this->select(array('code-projet' => $id));
		$row = $rowset->current();
		if (!$row) {
			throw new \Exception("Could not find row $id");
		}
		return $row;
	}
}

?>